package com.lingo.dingrobotutils.model.msgBuilder;

import com.dingtalk.api.request.OapiRobotSendRequest;

/**
 * @file: com.lingo.dingRobot.common.model.msgBuilder.DingLinkMsgBuilder
 * @Description: 封装 Link 消息类型
 * @author: lingo
 * @version: v1.0
 * @date: 2020/3/23 9:55
 * @Company: www.xyb2b.com
 */

public class DingLinkMsgBuilder extends MyDingMsgBuilder {

    private final OapiRobotSendRequest.Link link = new OapiRobotSendRequest.Link();

    public DingLinkMsgBuilder() {
        this.request.setMsgtype("link");
        this.request.setLink(link);
    }

    public DingLinkMsgBuilder setTitle(String title){
        if (title != null && !title.isEmpty()){
            this.link.setTitle(title);
        }
        return this;
    }

    public DingLinkMsgBuilder setLink(String link){
        if (link != null && !link.isEmpty()){
            this.link.setMessageUrl(link);
        }
        return this;
    }

    public DingLinkMsgBuilder setPic(String picUrl){
        if (picUrl != null && !picUrl.isEmpty()){
            this.link.setPicUrl(picUrl);
        }
        return this;
    }

    public DingLinkMsgBuilder setText(String text){
        if (text != null && !text.isEmpty()){
            this.link.setText(text);
        }
        return this;
    }

    @Override
    public OapiRobotSendRequest build() {
        request.setLink(link);
        return request;
    }
}
